import java.util.Arrays;

public class MyStack {
    //顺序栈
    public int[] elem;
    public int usedsize;
    public MyStack() {
        this.elem = new int[10];
    }
    //进栈
    public void push(int val){
        //容量满了就扩容
        if(isFull()){
            elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedsize] = val;
        usedsize++;
    }
    //判断容量
    public boolean isFull(){
        return elem.length == usedsize;
    }
    //出栈
    public int pop(){
        if(isFull()){
            throw new StackEmptyError("栈是空的");
        }
        int num = elem[usedsize-1];
        usedsize--;
        return num;
        //return elem[--usedsize];
    }
    //查看栈顶元素
    public int peek(){
        if(isFull()){
            throw new StackEmptyError("栈是空的");
        }
        return elem[--usedsize];
    }

    public boolean isEmpty(){
        return usedsize == 0;
    }
}
